package com.nuanshui.framework.behavior;

public class BaseBehavior<T> implements Behavior<T> {

	private T associatedObject;
	
	private boolean bAttached;
	
	public T getAssociatedObject()
	{
		return associatedObject;
	}
	
	 
	public void attach(T obj)
	{
		if(bAttached) return;
		if(obj!=null)
		{
			associatedObject=obj;
			onAttached();
			bAttached=true;
		}
	}
	public void detach()
	{
		if(!bAttached) return;
		
		onDetaching();
		
		bAttached=false;
		associatedObject=null;
	}
	
	protected void onAttached() {
	}

	protected void onDetaching()
	{

	}
}
